import com.pyrsana.faith.membership.Profile
import com.pyrsana.faith.membership.User
import com.pyrsana.faith.membership.SecRole
import com.pyrsana.faith.membership.SecUserSecRole
import com.pyrsana.faith.retreat.Location
import com.pyrsana.faith.retreat.Passage
import com.pyrsana.faith.retreat.Retreat
import com.pyrsana.faith.retreat.TransportationLeg
import com.pyrsana.faith.retreat.Workshop

class BootStrap {

    def springSecurityService
    
    def init = { servletContext ->
        // Create default roles:
        def adminRole = SecRole.findOrSaveWhere(authority:'ROLE_ADMIN')
        def directorRole = SecRole.findOrSaveWhere(authority:'ROLE_DIRECTOR')
        def counselorRole = SecRole.findOrSaveWhere(authority:'ROLE_COUNSELOR')
        def userRole = SecRole.findOrSaveWhere(authority:'ROLE_USER')
        
        // Default Admin User:
        //def defaultAdmin = User.findOrSaveWhere(enabled: true, username:'admin', password:'ChurchAdmin')
        if (User.count() == 0) {
            def defaultAdmin = new User(enabled: true, username:'admin', password:'ChurchAdmin').save(flush:true)
            SecUserSecRole.create(defaultAdmin, adminRole, true)
        }

        
        // Create default retreat:
        if (Retreat.count() == 0) {
            def dateFormat = 'MM/dd/yyyy hh:mm:ss aaa'
            def cxr2012 = new Retreat(name: 'Camp Crossroads', theme: 'One Love', cost: 160.00)
            cxr2012.location = new Location(name:'Camp Elim', streetAddress:'5567 Painted Rocks Road', city:'Woodland Park', state:'CO', zipcode:80863, url:'http://campelim.com/').save()
            cxr2012.startDate = Date.parse(dateFormat, '08/04/2012 08:00:00 AM MST')
            cxr2012.endDate = Date.parse(dateFormat, '08/07/2012 06:00:00 PM MST')
            cxr2012.description = "Camp Crossroads (CXR) was started in 2000 by Pastor Paul Epp of the Chinese Evangelical Church of Denver. Initially a joint venture between a few Chinese churches in the area, CXR has grown to be one of the highlights of the year for many Chinese church youth groups.  It provides a rare opportunity for Asian-American students and their friends to come together as one community and learn more about the faith they profess. It also provides a one-of-a-kind opportunity for many to introduce friends and peers to the Christian faith in a unique cultural context.  We expect CXR to change and grow as the years press on, but we hope that it will always be a powerful experience for those who attend, helping them to begin, strengthen, or refresh a relationship with our one true Savior, Jesus Christ."
            cxr2012.speakers = ''
            cxr2012.activities = "Face time with friends, worship, fellowship, eating, sleeping, reading, writing, playing and all that jazz. Free Time free activities include a zip line, ropes course, archery, swimming, group sports, and more. For a small fee you can make crafts or go canoeing."
            cxr2012.audience = "Students about to enter 7th grade through seniors in high school who graduated in May/June"
            cxr2012.whatToBring = "Bible, pen, notebook, sleeping bag or bedding, clothes, toiletries, towel, closed toed shoes (in addition to sandals if you wish), flashlight, swimsuit, sun screen, bug repellent."
            cxr2012.whatNotToBring = "Water balloons, knives, firearms, fireworks, slingshots, pea shooters, immodest clothing (includes swimsuits), electronic devices of any kind (includes cell phones and iPods)."
            cxr2012.notes = 'There will be a $25 late fee if registering after August 1, 2012. Please make checks payable to BCEFC and turn it in to any camp counselor or director.'
            
            Passage passage = new Passage(verses:'John 13:34', text:'A new command I give you: Love one another. As I have loved you, so you must love one another.', translation:'NIV')
            cxr2012.addToThemeVerses(passage)
            
            
            def cecd = new Location(name:'CECD', streetAddress:'1099 Newark St', city:'Aurora', state:'CO', zipcode:80010, url:'http://cecd.net/').save()
            cxr2012.addToTransportationLegs(new TransportationLeg(type:'Drop Off Location', meetingDate: Date.parse(dateFormat, '08/04/2012 08:00:00 AM MST'), location:cecd))
            cxr2012.addToTransportationLegs(new TransportationLeg(type:'Pick Up Location', meetingDate: Date.parse(dateFormat, '08/07/2012 05:00:00 PM MST'), location:cecd))
            
            def workshop1 = new Workshop(title:'Reflection of a Perfect Love', description:'In romantic relationships, we expect so much. Finding "the one" who will complete you and will share a life with you. But is love all that we expect it to be or are we missing the point? Are we simply settling for a Hollywood-bred romance? We were meant for so much more and our romantic relationships were meant to reflect a deeper, perfect Love.')
            def workshop2 = new Workshop(title:'Attitude of Servitude', description:'You can serve without loving God, but you can\'t truly love God without serving.')
            def workshop3 = new Workshop(title:'True Manhood', description:'')
            
            cxr2012.addToWorkshops(workshop1)
            cxr2012.addToWorkshops(workshop2)
            cxr2012.addToWorkshops(workshop3)
            
            if (!cxr2012.save(flush:true)) {
                log.error("Unable to create cxr2012")
            }
        }
    }
    def destroy = {
    }
}
